package com.cwits.wifi.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cwits.wifi.R;
import com.cwits.wifi.base.BaseFragment;
import com.cwits.wifi.ui.activity.HelpActivity;
import com.cwits.wifi.ui.activity.MainActivity;
import com.cwits.wifi.ui.activity.MyInfoActivity;
import com.cwits.wifi.ui.activity.PengCiActivity;
import com.cwits.wifi.ui.activity.StorageMgrActivity;
import com.cwits.wifi.ui.activity.VersionActivity;

import java.util.Locale;

/**
 * Created by ZhangHua on 16-03-01.
 */
public class LeftFragment extends BaseFragment implements View.OnClickListener {
    private View mView;
    private ImageView second_title_image_cilcle;
    private RelativeLayout mFirst_Rl, mSecond_Rl;
    private TextView mFirstTitleLeftView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_left, container, false);
        initView();
        return mView;
    }

    private void initView() {
        mFirst_Rl = (RelativeLayout) mView.findViewById(R.id.first_left_rl);
        mSecond_Rl = (RelativeLayout) mView.findViewById(R.id.second_left_rl);
        second_title_image_cilcle = (ImageView) mView.findViewById(R.id.second_title_image_cilcle);
        if (mApplication.getIsRegisterPengci())
            second_title_image_cilcle.setVisibility(View.INVISIBLE);
        mFirstTitleLeftView = (TextView) mFirst_Rl.findViewById(R.id.fistr_title_leftview);
        mFirstTitleLeftView.setVisibility(View.INVISIBLE);
        mFirst_Rl.setOnClickListener(this);
        mSecond_Rl.setOnClickListener(this);
        Locale locale = getResources().getConfiguration().locale;
        String language = locale.getLanguage();
        if (language.endsWith("zh")) {
//            mSecond_Rl.setVisibility(View.VISIBLE);
        } else {
            mSecond_Rl.setVisibility(View.GONE);
        }

        ((RelativeLayout) (mView.findViewById(R.id.rl_version))).setOnClickListener(this);
        ((RelativeLayout) (mView.findViewById(R.id.rl_storage))).setOnClickListener(this);
        ((RelativeLayout) (mView.findViewById(R.id.rl_help))).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.first_left_rl:
                MainActivity lma = (MainActivity) this.getActivity();
                if (lma.getIsCanGo() == false) {
                    showToast(getString(R.string.left_wait));
                    return;
                }

                this.getActivity().startActivity(new Intent(this.getActivity(), MyInfoActivity.class));
                break;
            case R.id.second_left_rl:
                MainActivity lms = (MainActivity) this.getActivity();
                if (lms.getIsCanGo() == false) {
                    showToast(getString(R.string.left_wait));
                    return;
                }

                this.getActivity().startActivity(new Intent(this.getActivity(), PengCiActivity.class));
                break;

            case R.id.rl_version:
                MainActivity lma1 = (MainActivity) this.getActivity();
                if (lma1.getIsCanGo() == false) {
                    showToast(getString(R.string.left_wait));
                    return;
                }
                this.getActivity().startActivity(new Intent(this.getActivity(), VersionActivity.class));
                break;
            case R.id.rl_storage:
                MainActivity lma2 = (MainActivity) this.getActivity();
                if (lma2.getIsCanGo() == false) {
                    showToast(getString(R.string.left_wait));
                    return;
                }
                this.getActivity().startActivity(new Intent(this.getActivity(), StorageMgrActivity.class));
                break;
            case R.id.rl_help:
                MainActivity lma3 = (MainActivity) this.getActivity();
                if (lma3.getIsCanGo() == false) {
                    showToast(getString(R.string.left_wait));
                    return;
                }
                this.getActivity().startActivity(new Intent(this.getActivity(), HelpActivity.class));
                break;
        }
    }

    public void setFirstTitleLeftView(int msmCount) {
        mFirstTitleLeftView.setText(String.valueOf(msmCount));
        if (msmCount == 0) {
            mFirstTitleLeftView.setBackgroundResource(R.drawable.transparent_circle_bg_15dp);
        } else {
            mFirstTitleLeftView.setBackgroundResource(R.drawable.red_circle_bg_15dp);
        }
    }

    public void displayNoPengciCilcle() {
        if (mApplication.getIsRegisterPengci())
            second_title_image_cilcle.setVisibility(View.INVISIBLE);
    }
}
